package com.jenkins.test.cron;

import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;

/**
 * @version V1.0.0
 * @ClassName: {@link ScheduleJobContext}
 * @Description: 定时器任务抽象
 * @author: Lanzhou
 * @date: 2021/6/28 15:14
 * @Copyright:2020 All rights reserved.
 */
@Component
public class ScheduleJobContext {

    private final ConcurrentHashMap<String, ScheduledFuture<?>> jobContext = new ConcurrentHashMap<>();

    /**
     * 添加
     *
     * @param key    标识
     * @param future 定时任务
     */
    public void setJobContext(String key, ScheduledFuture<?> future) {
        if (null != jobContext.get(key)) {
            return;
        }
        jobContext.put(key, future);
    }

    /**
     * 获取
     *
     * @param key 标识
     * @return
     */
    public ScheduledFuture<?> getJobContext(String key) {
        return jobContext.get(key);
    }

    /**
     * 删除
     *
     * @param key 标识
     */
    public void delJobContext(String key) {
        jobContext.remove(key);
    }


}
